home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PP_v1.4 / Source / ports.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  1KB  |  64 lines

  1. /* Ports.C - Port creating/freeing functions
  2. **
  3. ** Herein you will find CreatePort() and DeletePort(). It is quite possible
  4. ** that your stdlib already contains these, but just to make sure (and for
  5. ** the sake of example), here they are!
  6. **
  7. ** This file belongs to the Powerpacker Patcher project
  8. **
  9. ** Copyright 1991, Michael Berg
  10. */
  11.  
  12. #include <pragmas.h>
  13. #include <exec/types.h>
  14. #include <exec/ports.h>
  15. #include <exec/nodes.h>
  16. #include <exec/memory.h>
  17.  
  18. /* CreatePort() should exist in the standard library, but here it is, just
  19. ** in case your library lacks this function (it isn't in ROM)
  20. */
  21. struct MsgPort *myCreatePort(register char *name, register pri)
  22. {
  23.     register UBYTE sigbit;
  24.     register struct MsgPort *gotten;
  25.  
  26.     if
  27.     (
  28.         gotten = (struct MsgPort *)AllocMem
  29.                        (
  30.                         sizeof(*gotten),
  31.                         MEMF_CLEAR | MEMF_PUBLIC
  32.                        )
  33.     )
  34.     {
  35.         if ((sigbit = AllocSignal(-1)) != -1)
  36.         {
  37.             gotten->mp_Node.ln_Name = name;
  38.             gotten->mp_Node.ln_Pri  = pri;
  39.             gotten->mp_Node.ln_Type = NT_MSGPORT;
  40.             gotten->mp_Flags        = PA_SIGNAL;
  41.             gotten->mp_SigBit       = sigbit;
  42.             gotten->mp_SigTask      = FindTask(0);
  43.  
  44.             AddPort(gotten);
  45.  
  46.             return(gotten);
  47.         }
  48.         else
  49.             FreeMem((char *)gotten,sizeof(*gotten));
  50.     }
  51.  
  52.     return(NULL);
  53. }
  54.  
  55. /* DeletePort is also supposed to be in your standard library. Here it is,
  56. ** just in case...
  57. */
  58. void myDeletePort(register struct MsgPort *p)
  59. {
  60.     RemPort(p);
  61.     FreeSignal(p->mp_SigBit);
  62.     FreeMem((char *)p,sizeof(*p));
  63. }
  64.